package cn.itsource.hrm.service.impl;

import cn.itsource.hrm.domain.LoginUser;
import cn.itsource.hrm.domain.UserMeal;
import cn.itsource.hrm.mapper.LoginUserMapper;
import cn.itsource.hrm.mapper.UserMealMapper;
import cn.itsource.hrm.service.ILoginUserService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author terrylv
 * @since 2021-04-28
 */
@Service
public class LoginUserServiceImpl extends ServiceImpl<LoginUserMapper, LoginUser> implements ILoginUserService {
    @Autowired
    private LoginUserMapper userMapper;
    @Autowired
    private UserMealMapper userMealMapper;
    @Override
    public boolean insert(LoginUser entity) {
        //先保存loginUser
        userMapper.insert(entity);
      // 再保存t_user_meal
        UserMeal userMeal = new UserMeal();
        userMeal.setMealId(entity.getMealId());
        userMeal.setLoginId(entity.getId());
        userMeal.setExpireDate(new Date());
        userMeal.setState(0);
        userMealMapper.insert(userMeal);
        return true;
    }
}
